#ifndef GLOBALVAR_H
#define GLOBALVAR_H

#include <QModbusClient>
#include <QSerialPort>

namespace GlobalVar
{

    struct SerialSettings
    {
        enum ConnectionEnum{
            Serial,
            TCP
        };

        //
        ConnectionEnum connectType = ConnectionEnum::Serial;

        // serial
        QString portName = "COM1";
        int parity = QSerialPort::NoParity;
        int baud = QSerialPort::Baud9600;
        int dataBits = QSerialPort::Data8;
        int stopBits = QSerialPort::OneStop;

        // network
        QString url="127.0.0.1";
        int port=502;

        //
        int responseTime = 1000;
        int numberOfRetries = 3;
    };

    struct ModbusSetting
    {
    //寄存器数量
    #define Signed_Size 1
    #define Unsigned_Size 1
    #define Long_Size 2
    #define Float_Size 2
    #define Double_Size 4

        enum TypeEnum{
            Signed,
            Unsidned,
            Long,
            Float,
            Double
        };

        QModbusDataUnit::RegisterType registerType = QModbusDataUnit::HoldingRegisters;
        int serverAddr =1;
        int readStartAddr=0;
        TypeEnum readType=TypeEnum::Signed;
        int readValueCount = Signed_Size; // 寄存器数量
    };
    extern SerialSettings g_serialSetting;
    extern ModbusSetting g_modbusSetting;
}

#endif // GLOBALVAR_H
